package java8;

import java.util.*;
import java.util.Map.Entry;

public class Q5_4 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Map<String, TreeSet<Integer>> dict = new TreeMap<String, TreeSet<Integer>>();
		Map<Integer, String> dict1 = new TreeMap<Integer, String>();
		int e = 1;
		while (in.hasNextLine()) {
			String str = in.nextLine();
			if (str.equals("!!!!!")) {
				break;
			} else {
				Scanner sc = new Scanner(str);
				dict1.put(e, str);
				while (sc.hasNext()) {
					String key = sc.next();
					if (dict.get(key) == null) {
						TreeSet<Integer> row = new TreeSet<Integer>();
						row.add(e);
						dict.put(key, row);
					} else {
						dict.get(key).add(e);
					}
				}
				sc.close();
			}
			e++;
		}
		for (Entry<String, TreeSet<Integer>> entry : dict.entrySet()) {
			System.out.println(entry);
		}
		while (in.hasNextLine()) {
			String str1 = in.nextLine();
			if (str1.length() == 0) {
				System.out.println("found 0 results");
				continue;
			}
			Scanner sc = new Scanner(str1);
			String str2 = sc.next();
			if (!dict.containsKey(str2)) {
				System.out.println("found 0 results");
				continue;
			}
			TreeSet<Integer> row = dict.get(str2);
			while (sc.hasNext()) {
				String key = sc.next();
				row.retainAll(dict.get(key));
			}
			if (row.isEmpty()) {
				System.out.println("found 0 results");
			} else {
				System.out.println(row);
				for (Integer n : row) {
					System.out.println("line " + n + ":" + dict1.get(n));
				}
			}
			sc.close();
		}
		in.close();
	}

}
